package io.renren.modules.noc.service.impl;
import io.renren.modules.sys.entity.SysUserEntity;
import io.renren.modules.sys.shiro.ShiroUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.noc.dao.NocBusinessDao;
import io.renren.modules.noc.entity.NocBusinessEntity;
import io.renren.modules.noc.service.NocBusinessService;


@Service("nocBusinessService")
public class NocBusinessServiceImpl extends ServiceImpl<NocBusinessDao, NocBusinessEntity> implements NocBusinessService {

    @Autowired
    private NocBusinessDao dao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        SysUserEntity userEntity = ShiroUtils.getUserEntity();
        String mobile = (String)params.get("mobile");
        String company = (String)params.get("company");
        String templateId = (String)params.get("templateId");
        String isman = (String)params.get("isman");
        IPage<NocBusinessEntity> page = this.page(
                new Query<NocBusinessEntity>().getPage(params),
                new QueryWrapper<NocBusinessEntity>()
                        .eq(!"admin".equals(userEntity.getUsername())&&!"jn502".equals(userEntity.getUsername()),"ly",userEntity.getRemark())
                        .eq("tid",templateId)
                        .eq(StringUtils.isNotEmpty(isman),"isman",isman)
                        .like(StringUtils.isNotBlank(mobile),"mobile", mobile)
                        .like(StringUtils.isNotBlank(company),"company", company)
        );



        return new PageUtils(page);
    }

    @Override
    public String getNextErCode(String pre){
        return dao.getNextErCode(pre);
    }


    public Integer getMemberCount(Map<String,Object> map){
        return dao.getMemberCount(map);
    }

    public Integer getMember(Map<String,Object> map){
        return dao.getMember(map);
    }

    public void updateCompany(Map<String,Object> map){ dao.updateCompany(map);}

    public Map<String,Object> getMpMax(Map<String,Object> map){return  dao.getMpMax(map);}

    public  Map<String,Object> getMemberId(Map<String,Object> map){return dao.getMemberId(map);};


    public void updateSign(Map<String,Object> map){
        dao.updateSign(map);
    }

    public Integer selectCount(Map<String,Object> map){
        return dao.selectCount(map);
    }

    public List<NocBusinessEntity> getErcodeByOpenId(Map<String,Object> map){
        return dao.getErcodeByOpenId(map);
    }

}
